package qeug.shsh.task;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.MainEntityType;
import kd.bos.entity.flex.FlexEntireData;
import kd.bos.entity.flex.FlexEntityMetaUtils;
import kd.bos.entity.flex.FlexProperty;
import kd.bos.entity.operate.result.OperationResult;
import kd.bos.entity.property.FlexProp;
import kd.bos.exception.KDException;
import kd.bos.flex.FlexService;
import kd.bos.orm.ORM;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.schedule.executor.AbstractTask;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import org.apache.flink.types.parser.IntParser;
import qeug.shsh.bpm.Factory.ThirdServiceFactory;
import qeug.shsh.bpm.service.SAPService;
import qeug.shsh.helper.FacadeHelper;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.logging.SimpleFormatter;
import java.util.stream.Collectors;

/**
 * @projectName: qeug-cosmic-root-project
 * @package: qeug.shsh.task
 * @className: SAPVoucherTaskPlugin
 * @author: wenyx
 * @description: TODO
 * @date: 2025/2/14 16:30
 * @version: 1.0
 */
public class SAPVoucherTaskPlugin extends AbstractTask {
    @Override
    public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {

        try {
            SAPService sapService = ThirdServiceFactory.createSAPService();
            QFilter[] qFilters = new QFilter[]{new QFilter("qeug_objectkey", QCP.equals, "")};
            DynamicObject[] vouchers = BusinessDataServiceHelper.load("gl_voucher", "id", qFilters);
            for (DynamicObject voucher : vouchers) {
                long id = voucher.getLong("id");
                QFilter[] qFilter = new QFilter[]{new QFilter("id", "=", id)};
                DynamicObject gl_voucher = BusinessDataServiceHelper.loadSingle("gl_voucher", qFilters);
                sapService.voucher(gl_voucher);
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

}
